<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
                   xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
    <!-- author: caspar -->
    <!-- description: for liquibase auto create drop modify mysql database table -->
    <!-- auto generate template -->
    <changeSet author="caspar" id="create-table-${model.name}">
        <createTable tableName="${model.name}" remarks="${model.remark}">
            <#list model.fields as field>
            <column name="${field.name}" type="${field.type}" remarks="${field.remark}" ${(field.defaultValue???then("defaultValueComputed=\"${field.defaultValue}\"",""))}>
                <constraints nullable="${field.nullable?c}"/>
            </column>
            </#list>
        </createTable>
        <#if model.primaryKey.isPresent()>
        <addPrimaryKey columnNames="${model.primaryKey.get().columns}"
                       constraintName="${model.primaryKey.get().name}"
                       tableName="${model.primaryKey.get().tableName}" />
        </#if>
        <#list model.indexes as index>
        <createIndex unique="${index.uniqueFlag?string("true","false")}" tableName="${index.tableName}" indexName="${index.name}">
            <#list index.columns as column>
            <column name="${column}" />
            </#list>
        </createIndex>
        </#list>
    </changeSet>
</databaseChangeLog>
